package com.example.demo.controller;

import com.example.demo.enums.View;
import com.example.demo.util.NavUtil;
import de.felixroske.jfxsupport.FXMLController;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.layout.Pane;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * @Author hweiyu
 * @Description
 * @Date 2022/6/23 10:10
 */
@FXMLController
public class MainController implements Initializable {

    @FXML
    private Pane mainPane;

    /**
     * 初始化
     * @param location
     * @param resources
     */
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        toWelcome(null);
    }

    /**
     * action
     * @param event
     */
    @FXML
    public void toWelcome(Event event) {
        go(NavUtil.getView(View.WELCOME));
    }

    @FXML
    public void toData(Event event) {
        go(NavUtil.getView(View.DATA_INDEX));
    }

    @FXML
    public void toAbout(Event event) {
        go(NavUtil.getView(View.ABOUT));
    }

    private void go(Parent view) {
        mainPane.getChildren().clear();
        mainPane.getChildren().add(view);
    }

    @FXML
    public void doClose(Event event) {
        Platform.exit();
    }

}
